from django.shortcuts import render
from requests import Response
from rest_framework.generics import CreateAPIView
from rest_framework.views import APIView
from .serializers import CreatUserSerialzier
from .models import *
# Create your views here.
class UserView(CreateAPIView):
    """用户注册"""
    serializer_class = CreatUserSerialzier


class UsernameCountView(APIView):
    """判断用户是否被注册"""
    def get(self, request,username):
        # 查询user表
        count = User.objects.filter(username=username).count()
        # 包装响应数据
        data={
            'username':username,
            'count':count
        }
        return Response(data)

class UserMobileCountView(APIView):
    """判断手机号是否被注册"""
    def get(self, request,mobile):
        count=User.objects.filter(mobile=mobile).count()
        data={
            'mobile':mobile,
            'count':count
        }
        return Response(data)